﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SqlServer.Types;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
using SensorNetworkUI;

namespace WebAccess
{
    public partial class RegisterSensor : System.Web.UI.Page
    {
        SensorNetworkUI.SensorStructure sensor = new SensorNetworkUI.SensorStructure();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
                Map1.MapUnit = GeographyUnit.DecimalDegree;
                Map1.MapTools.OverlaySwitcher.Enabled = true;
                Map1.MapTools.MouseCoordinate.Enabled = true;
             

                WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
                Map1.CustomOverlays.Add(worldMapKitOverlay);
             

                ContextMenu onmap = new ContextMenu();
                ContextMenuItem pos = new ContextMenuItem("Add Sensor Here");
                pos.Click += new EventHandler<ContextMenuItemClickEventArgs>(showpos);
                onmap.MenuItems.Add(pos);

                Map1.ContextMenu = onmap;
                

                //Map1. += new EventHandler<MapClickedEventArgs>(Map1_DoubleClick);




            }

        }
        private void showpos(object sender, ContextMenuItemClickEventArgs e)
        {
            //  this.Page.Title = e.Location.X.ToString();

            this.sensor = new SensorStructure();
            sensor.Longitude = e.Location.X;
            sensor.Lattitude = e.Location.Y;
            location.Text = sensor.Longitude + "," + sensor.Lattitude;

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SensorStructure sens = new SensorStructure();
            sens.Id = int.Parse(DropDownList1.SelectedValue);


            string[] latlon = location.Text.Split(',');
            sens.Lattitude = Double.Parse(latlon[1]);
            sens.Longitude = Double.Parse(latlon[0]);


            sens.UpdateLocation();
        }
    }
}